<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('商品列表(设备申领)')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>设备类型：</label>
                            <select name="devType" th:with="type=${@dict.getType('sys_device_type')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li>
                            <label style="width: 105px;">上下架状态：</label>
                            <select name="onOffStatus" th:with="type=${@dict.getType('sys_item_on_off_status')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li class="select-time">
                            <label style="width: 105px;">创建时间：</label>
                            <input type="text" class="time-input" id="startTime" placeholder="开始时间"
                                   name="startTime"/>
                            <span>-</span>
                            <input type="text" class="time-input" id="endTime" placeholder="结束时间"
                                   name="endTime"/>
                        </li>
                        <li>
                            <label style="width: 105px;">关键字查询字段：</label>
                            <select name="fields">
                                <option value="itemName" selected>商品名称</option>
                            </select>
                            <input type="text" name="keywords"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="system:items:addDevApplyItem">
                <i class="fa fa-plus"></i> 添加
            </a>
            <a class="btn btn-primary" onclick="selectFirstColumnsOn()"
               shiro:hasPermission="system:items:on_off_status">
                <i class="fa fa-check"></i> 批量上架
            </a>
            <a class="btn btn-danger" onclick="selectFirstColumnsOff()"
               shiro:hasPermission="system:items:on_off_status">
                <i class="fa fa-close"></i> 批量下架
            </a>
            <!--<a class="btn btn-primary single disabled" onclick="$.operate.edit()"-->
            <!--shiro:hasPermission="system:items:edit">-->
            <!--<i class="fa fa-edit"></i> 修改-->
            <!--</a>-->
            <!--<a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()"-->
            <!--shiro:hasPermission="system:items:remove">-->
            <!--<i class="fa fa-remove"></i> 删除-->
            <!--</a>-->
            <!--<a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:items:export">-->
            <!--<i class="fa fa-download"></i> 导出-->
            <!--</a>-->
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('system:items:editDevApplyItem')}]];

    var removeFlag = [[${@permission.hasPermi('system:items:remove')}]];

    var purposeDatas = [[${@dict.getType('sys_item_purpose')}]];
    var onOffStatusDatas = [[${@dict.getType('sys_item_on_off_status')}]];

    var devTypeDatas = [[${@dict.getType('sys_device_type')}]];

    var prefix = ctx + "system/items";

    $(function () {
        var options = {
            url: prefix + "/devApplyItemsList",
            createUrl: prefix + "/addDevApplyItem",
            updateUrl: prefix + "/editDevApplyItem/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "商品",
            columns: [{
                checkbox: true
            },
                {
                    field: 'id',
                    title: '',
                    visible: false
                },
                {
                    field: 'imgUrl',
                    title: '商品照片',
                    formatter: function (value, row, index) {
                        return $.table.imageView(row.imgUrl);
                    }
                },
                {
                    field: 'itemName',
                    title: '商品名称'
                },
                {
                    field: 'devType',
                    title: '设备类型',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(devTypeDatas, value);
                    }
                },
                {
                    field: 'onOffStatus',
                    title: '上下架状态',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(onOffStatusDatas, value);
                    }
                },
                {
                    field: 'createdTime',
                    title: '创建时间'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    function selectFirstColumnsOn() {
        var column = $.table.selectFirstColumns();
        if (column == null || column == "") {
            layer.msg("您未选择商品");
            return;
        }
        var ids = "";
        for (var i = 0; i < column.length; i++) {
            ids = ids + column[i] + ",";
        }
        var str = "确认上架商品?";
        var url = prefix + "/onOffItems";
        var data = {
            "ids": ids,
            "on_off_status": 1,
        };
        $.modal.confirm(str, function () {
            $.operate.submit(url, "post", "json", data);
        });
    }

    function selectFirstColumnsOff() {
        var column = $.table.selectFirstColumns();
        if (column == null || column == "") {
            layer.msg("您未选择商品");
            return;
        }
        var ids = "";
        for (var i = 0; i < column.length; i++) {
            ids = ids + column[i] + ",";
        }
        var str = "确认下架商品?";
        var url = prefix + "/onOffItems";
        var data = {
            "ids": ids,
            "on_off_status": 2,
        };
        $.modal.confirm(str, function () {
            $.operate.submit(url, "post", "json", data);
        });
    }
</script>
</body>
</html>